#!/bin/sh
printf 'Running harec test suite at %s\n\n' "$(date)"
start=$(date +"%s")

ntests=0
npass=0
nfail=0

for f in ./tests/*
do
	if [ -x "$f" ] && [ "$f" != "./tests/run" ]
	then
		ntests=$((ntests+1))
		name="$(basename "$f")"
		printf '%-20s ...' "$name"
		if [ "$name" = "09-funcs" ]
		then
			expected=42
		else
			expected=0
		fi
		$f
		if [ $? -eq $expected ]
		then
			npass=$((npass+1))
			printf 'PASS\n'
		else
			nfail=$((nfail+1))
			printf 'FAIL\n'
		fi
	fi
done

finish=$(date +"%s")
printf '\n%d tests:\t%d passed\t%d failed\tin %d seconds\n' \
	$ntests $npass $nfail $((finish-start))
if [ $nfail -ne 0 ]
then
	exit 1
fi
